package com.apache.flow.core.dao;

import org.springframework.stereotype.Repository;

import com.apache.core.orm.hibernate.ApacheBaseDao;
import com.apache.flow.core.entity.FlowAutomaticProcessing;

@Repository
public class FlowAutomaticProcessingDao extends ApacheBaseDao<FlowAutomaticProcessing, String> {
	/**
	 * 
	 * @param processInsId 流程实例Id
	 * @param status 状态
	 * <p>@description 根据流程实例Id修改自处理表中对应实例任务的状态
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-8-21 下午05:32:38
	 */
	public int updateAutomaticProcessingStatus(String processInsId, String status) {
		String sql = "update flow_automatic_processing t set t.handle_status='" + status + "' where t.processins_id='"
				+ processInsId + "' ";
		return this.getSession().createSQLQuery(sql).executeUpdate();
	}

	/**
	 * 
	 * @param processInsId 流程实例Id
	 * @return
	 * <p>@description 根据实例Id删除流程实例的自处理任务
	 * <p>@version 1.0
	 * <p>@author lvcai
	 * <p>@update 2013-8-21 下午05:42:53
	 */
	public int deleteAutomaticProcessingByProcessInsId(String processInsId) {
		String sql = "delete from flow_automatic_processing t where t.processins_id='" + processInsId + "'";
		return this.getSession().createSQLQuery(sql).executeUpdate();
	}

	public boolean checkAutoTaskIfValid(String processInsId) {
		boolean mark = true;
		String sql = "select * from jbpm4_execution t where t.id_ ='" + processInsId + "'";
		int resultNum = this.getSession().createSQLQuery(sql).executeUpdate();
		if (resultNum == 0) {
			mark = false;
		}
		return mark;
	}

}
